package com.demo2do.fms.admin.entity.search.supplier;

import java.util.List;
import java.util.Map;

import com.demo2do.core.persistence.support.QueryBuilder;
import com.demo2do.core.persistence.support.QueryFilter;
import com.demo2do.core.persistence.support.QueryOrder;
import com.demo2do.fms.entity.driver.DriverAuditStatus;

/**
 *
 * @author Ark
 *
 */
public class DriverSearch implements QueryBuilder {
    
    /** 供方id */
    private Long supplierId;
    
    /** 审核状态 */
    private DriverAuditStatus status;

    /** 姓名 */
    private String name;

    /** 职务Id */
    private Long dutyId;

    /** 工号 */
    private String code;

    /** 身份证 */
    private String citizenCode;

    /** 车辆ID */
    private Long vehicleId;

    /** 手机号 */
    private String mp;

    /** 是否激活 */
    private Boolean active;
    
    /** 是否绑定车辆 */
    private Boolean bind;

    private QueryOrder queryOrder;

    private QueryFilter queryFilter;

    /**
     * The default constructor
     */
    public DriverSearch() {
        queryOrder = new QueryOrder();
    }

    /* (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#getPreparedFilter(boolean)
     */
    public QueryFilter getPreparedFilter(boolean refresh) {

        if (queryFilter == null || refresh) {

            queryFilter = new QueryFilter().addEquals("supplier.id", supplierId)
                                           .addEquals("status", status)
                                           .addLike("name", name)
                                           .addEquals("dutyId", dutyId)
                                           .addEquals("code", code)
                                           .addEquals("citizenCode", citizenCode)
                                           .addEquals("vehicleId", vehicleId)
                                           .addLike("mp", mp)
                                           .addEquals("active", active)
                                           .addEquals("bind", bind)
                                           .addEquals("disabled", false);
        }
        
        return queryFilter;
        
    }
    
    /**
     * 
     * @param supplierIds
     */
    public void addSupplierId(List<Long> supplierIds) {
        supplierIds.add(0L);
        this.getPreparedFilter(false).addSentence("supplier.id IN (:supplierIds)", "supplierIds", supplierIds);
    }

    /* (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#getOrder()
     */
    public QueryOrder getOrder() {
        return queryOrder;
    }

    /* (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#buildSentenceTemplate()
     */
    public String buildSentenceTemplate() {
        String sentence = " FROM Driver " + getPreparedFilter(false).whereSentence() + queryOrder.sentence();
        return sentence;
    }

    /*
     * (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#buildParameters()
     */
    public Map<String, Object> buildParameters() {
        return getPreparedFilter(false).parameters();
    }
    
    /**
     * @return
     */
    public QueryFilter getQueryFilter(){
        return getPreparedFilter(false);
    }
    
    /**
     * @return
     */
    public Long getSupplierId() {
        return supplierId;
    }
    
    /**
     * @return
     */
    public DriverAuditStatus getStatus() {
        return status;
    }

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @return the dutyId
     */
    public Long getDutyId() {
        return dutyId;
    }

    /**
     * @return the code
     */
    public String getCode() {
        return code;
    }

    /**
     * @return the citizenCode
     */
    public String getCitizenCode() {
        return citizenCode;
    }

    /**
     * @return the vehicleId
     */
    public Long getVehicleId() {
        return vehicleId;
    }

    /**
     * @return the mp
     */
    public String getMp() {
        return mp;
    }

    /**
     * @return
     */
    public Boolean getActive() {
        return active;
    }
    
    /**
     * @return
     */
    public Boolean getBind() {
        return bind;
    }
    
    /**
     * @param supplierId
     */
    public void setSupplierId(Long supplierId) {
        this.supplierId = supplierId;
    }
    
    /**
     * @param status
     */
    public void setStatus(DriverAuditStatus status) {
        this.status = status;
    }
    
    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * @param dutyId the dutyId to set
     */
    public void setDutyId(Long dutyId) {
        this.dutyId = dutyId;
    }

    /**
     * @param code the code to set
     */
    public void setCode(String code) {
        this.code = code;
    }

    /**
     * @param citizenCode the citizenCode to set
     */
    public void setCitizenCode(String citizenCode) {
        this.citizenCode = citizenCode;
    }

    /**
     * @param vehicleId the vehicleId to set
     */
    public void setVehicleId(Long vehicleId) {
        this.vehicleId = vehicleId;
    }

    /**
     * @param mp the mp to set
     */
    public void setMp(String mp) {
        this.mp = mp;
    }

    /**
     * @param active
     */
    public void setActive(Boolean active) {
        this.active = active;
    }
    
    /**
     * @param bind
     */
    public void setBind(Boolean bind) {
        this.bind = bind;
    }
    
}